home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2000 February / Macworld (2000-02).dmg / Games World / Hot demos! / Starbound II / AI agents / Gypsum 1.00 / Gypsum 1.00.rsrc / ss$t_148 < prev   
Text File  |  1999-10-30  |  4KB  |  152 lines

  1. situation planet_production
  2. vars
  3.    p : planet;
  4.    i : integer;
  5.    st : integer;
  6.    success : boolean;
  7.    hex : integer;
  8.    struct : structure;
  9.  
  10. function Find_empty_hex(p : planet) : integer;
  11. vars
  12.    target : integer;
  13.    
  14. begin
  15.    target := Random(127);
  16.    while (Hex_structure(p, target) <> nil) do
  17.       target := Random(127);
  18.    return(target);
  19. end;
  20.  
  21.  
  22. // Main function
  23. begin
  24.    p := This_planet();
  25.    // First set the tech spending levels
  26.    Set_weapon_spending(p, w_spending);
  27.    Set_shield_spending(p, s_spending);
  28.    Set_move_spending(p, m_spending);
  29.    Set_detect_spending(p, d_spending);
  30.    Set_develop_spending(p, 50);
  31.    // Now see if we want to build a ship
  32.    if ((Planet_weapon(p) > tech_min) and
  33.        (Planet_shield(p) > tech_min) and
  34.        (Planet_move(p) > tech_min) and
  35.        (Planet_detect(p) > tech_min)) then
  36.       Set_ship_spending(p, 100);
  37.    else
  38.       Set_ship_spending(p, 0);
  39.    
  40.    // If there are more then two ships, then send out a squad
  41.    if (Orbit_num_ships(p) >= fleet_size+1) then
  42.       begin
  43.          i := 1;     // Don't want to send starbase
  44.          while (i < Orbit_num_ships(p)) do
  45.             begin
  46.                success := Orbit_depart(p, i, true);
  47.                i := i + 1;
  48.             end;
  49.       end;
  50.  
  51.    // If a new ship has been built then set the ship type
  52.    if (New_ship(p)) then
  53.       begin
  54.          i := 0;
  55.          while (Can_build_ship_type(p, i)) do
  56.             i := i + 1;
  57.          if (i > 0) then
  58.             begin
  59.                st := Random(i);
  60.                success := Construct_ship_type(p, st);
  61.             end;
  62.          
  63.          // Now set the troops to fill it
  64.          i := 0;
  65.          while (i < 8) do
  66.             begin
  67.                success := Stardock_set_manifest(p, i, 0);
  68.                i := i + 1;
  69.             end;
  70.          // Now refill the ship, try one of each
  71.          // repeat until the lowest troop fails
  72.          success := true;
  73.          while (success) do
  74.             begin
  75.                success := false;
  76.                i := 7;
  77.                while (i > 0) do
  78.                   begin
  79.                      if (Can_build_troop(p, i)) then
  80.                         success := success or Stardock_set_manifest(p, i, Stardock_get_manifest(p, i)+1);
  81.                      i := i - 1;
  82.                   end;
  83.             end;
  84.        end;
  85.    
  86.    // If there are 0 projects, then build a barracks or space port.
  87.    if (Num_projects(p) = 0) then
  88.       begin
  89.          if (Num_structures(p, 10) < 6) then       // space port
  90.             begin
  91.                // Select a random hex
  92.                hex := Find_empty_hex(p);
  93.                success := Create_structure(p, hex, 10);
  94.             end;
  95.          if (Num_structures(p, 2) < 6) then        // barracks
  96.             begin
  97.                // Select a random hex
  98.                hex := Find_empty_hex(p);
  99.                success := Create_structure(p, hex, 2);
  100.             end;
  101.       end;
  102.       
  103.    // See if we need to reorganize the barracks
  104.    if ((New_structure(p)) or (New_troop(p))) then
  105.       begin
  106.          struct := First_structure(p);
  107.          while (struct <> nil) do
  108.             begin
  109.  //        if ((Structure_has(My_race(), Structure_type(p,struct),106)) and (Structure_left(p, struct) = 0)) then
  110.          if (Structure_has(My_race(), Structure_type(p,struct), 106)) then
  111.                   begin
  112.                      // Clear the old troops in the barracks
  113.                      i := 1;
  114.                      while (i < 8) do
  115.                         begin
  116.                            success := Set_barracks(p, struct, i, 0);
  117.                            i := i + 1;
  118.                         end;
  119.                      // Now refill the barracks, try one of each
  120.                      // repeat until the lowest troop fails
  121.                      success := true;
  122.                      while (success) do
  123.                         begin
  124.                            success := false;
  125.                            i := 7;
  126.                            while (i > 0) do
  127.                               begin
  128.                                  if (Can_build_troop(p, i)) then
  129.                                     success := success or Set_barracks(p, struct, i, Get_barracks(p, struct, i)+1);
  130.                                  i := i - 1;
  131.                               end;
  132.                         end;
  133.                   end;
  134.                struct := Next_structure(p, struct);
  135.             end;
  136.       end;
  137. end;
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.